<!--
- Author:   .
- Date:    2018/1/19 0019.
- File:    withdrawHistory.
-->
<template>
  <div class="Web_Box">
    <div class="account_tab2">
      <ul class="f-cb">
        <li :class="{'on': type == $dictionary.withdrawStatus.waiting}" @click="switchDrawStatus($dictionary.withdrawStatus.waiting)">提现中</li>
        <li :class="{'on': type == $dictionary.withdrawStatus.resolve}" @click="switchDrawStatus($dictionary.withdrawStatus.resolve)">已提现</li>
        <li :class="{'on': type == $dictionary.withdrawStatus.reject}" @click="switchDrawStatus($dictionary.withdrawStatus.reject)">其他</li>
      </ul>
    </div>
    <div class="DistributionOrder">
      <div class="present" style="margin-top: 5px;"
        v-infinite-scroll="loadMore"
        infinite-scroll-disabled="false"
        infinite-scroll-distance="0"
        infinite-scroll-immediate-check="false">
        <!--<p class="montis f-cb" v-show="type == this.$dictionary.withdrawStatus.waiting">当前提现中总金额：{{memberInfo.pre_withdrawals_amount}}元</p>-->
        <!--<p class="montis" v-show="type == $dictionary.withdrawStatus.resolve">当前已提现金额：{{memberInfo.ok_withdrawals_amount}}元</p>-->
        <div v-for="history in historyList.data">
          <div class="Presentrecord">
            <div class="presen f-cb"><span>{{history.account_name}}</span>
              <span class="Amount" v-show="type == $dictionary.withdrawStatus.waiting || type == $dictionary.withdrawStatus.reject">{{history.state | withdrawStatusTxt}}</span>
              <span class="Amount" v-show="type == $dictionary.withdrawStatus.resolve">已打款</span>
              <span class="Amount" v-show="type == $dictionary.withdrawStatus.reject">{{history.state | withdrawStatusTxt}}</span>
            </div>
            <div class="precord">
              <p>提现金额：<span class="">{{history.withdrawals_amount}}元</span></p>
              <p>提现手续费：<span class="">-{{(history.withdrawals_amount * history.w_rate) | toFixed(2)}}元</span></p>
              <p>实际到账金额：<span class="cr_f97e4e">{{history.amount}}元</span></p>
              <p>开户行：{{history.bank_name}}</p>
              <p>银行卡号：{{history.member_bank_num}}</p>
              <p>手机号码：{{history.member_mobile}}</p>
              <p>申请时间：{{history.add_time | timestampToDate('yyyy-MM-dd hh:mm:ss')}}</p>
              <p v-show="history.state == $dictionary.withdrawStatus.reject && history.remark">说明：{{history.remark}}</p>
              <!--<p>预计到账时间：{{history.pre_arrive_time | timestampToDate('yyyy-MM-dd hh:mm:ss')}}</p>-->
            </div>
          </div>
        </div>
      </div>
    </div>
    <loading-more :allLoaded="historyList.allLoaded" :show="historyList.data.length > 0"></loading-more>
    <empty-data :show="historyList.allLoaded && historyList.data.length <= 0"></empty-data>
    <footer-tab></footer-tab>
  </div>
</template>

<script>
  import {mapModules, mapRules} from 'vuet'

  export default{
    mixins: [
      mapModules({memberInfo: 'memberInfo'}),
      mapRules({need: ['memberInfo']})
    ],
    data() {
      return {
        type: this.$route.query.type || this.$dictionary.withdrawStatus.waiting,
        historyList: {requested: false, loading: false, allLoaded: false, page: 1, pageSize: 10, data: []}
      }
    },
    components: {},
    created() {
      this.initBalanceHistory()
    },
    watch: {
      $route () {
        this.type = this.$route.query.type
        this.initBalanceHistory(this.historyList.page, this.historyList.pageSize)
      }
    },
    methods: {
      switchDrawStatus(value) {
        this.$router.replace({name: 'balance-history', query: {type: value}})
      },
      initBalanceHistory() {
        this.historyList = {requested: false, loading: false, allLoaded: false, page: 1, pageSize: 10, data: []}
        this.getWithdrawHistory(this.historyList.page, this.historyList.pageSize)
      },
      getWithdrawHistory(page, pageSize) {
        this.historyList.loading = true
        let params = {is_remittance: this.type, page: page, pageSize: pageSize}

        this.$request.getWithdrawHistory(params).then(data => {
          if (data.length < this.historyList.pageSize) {
            this.historyList.allLoaded = true
          }
          this.historyList.data = [...this.historyList.data, ...data]
        }).finally(() => {
          this.historyList.requested = true
          this.historyList.loading = false
        })
      },
      loadMore() {
        if (this.historyList.loading || this.historyList.allLoaded) { // 正在加载 或 已取得全部数据
          return
        }
        setTimeout(() => {
          this.getWithdrawHistory(++this.historyList.page, this.historyList.pageSize)
        }, 500)
      }
    }
  }
</script>

<style>

</style>